package re56.layer;

import re56.packet.PDCCHPacket;
import re56.packet.PDSCHPacket;
import re56.packet.PUSCHPacket;
import re56.packet.Packet;

public class ENBPhysicalLayer extends PhysicalLayer
{

	public ENBPhysicalLayer(MACLayer Mac, RadioLayer radioLayerDL, RadioLayer radioLayerUL)
	{
		super(Mac, radioLayerDL, radioLayerUL);
	}
	
	@Override
	public void send(Packet p)
	{
		// let's write the packet into the DL Radio Layer.
		
		if(p instanceof PDCCHPacket)
		{
			radioLayerDL.writeInPDCCH((PDCCHPacket) p);
		}
		else if(p instanceof PDSCHPacket)
		{
			radioLayerDL.writeInPDSCH((PDSCHPacket) p);
		}
	}
	
	@Override
	public void receive()
	{
		// this function is called on each sub-frame. (should be 1ms)
		// as we're in the eNB PhysicalLayer,
		// we have to read into the Uplink Radio Layer.
		
		// first check the PUSCH Channel
		// User Data
		PUSCHPacket pusch = radioLayerUL.readInPUSCH();
		
		if(pusch != null)
			Mac.receivePacket(pusch);
		
	}
}
